package org.kev.transit;

import org.kev.transit.util.TransitConst;

import android.app.Activity;
import android.app.AlertDialog;
import android.view.KeyEvent;
import android.view.Menu;

/**
 * Most of my Activity extend this class.  It provides basic methods shared by all activities.
 * Such as common menus etc.
 * @author kevin
 *
 */
public abstract class DataActivity extends Activity implements Navigateable{
	public static final int ABOUT_ID = Menu.FIRST;
	public static final int SETTING_ID =  Menu.FIRST+1;
	public static final int FIRST_MENU = SETTING_ID ;
	
	/**
	 * Called by a background worker thread to do some work in the background without 
	 * blocking the main the main UI thread.
	 */
	public abstract void setData();

	/**
	 * Called when your activity's options menu needs to be created.
	 * 
	 * @param menu
	 */
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		super.onCreateOptionsMenu(menu);

		// We are going to create two menus. Note that we assign them
		// unique integer IDs, labels from our string resources, and
		// given them shortcuts.
		menu.add(0, ABOUT_ID, R.string.about_menu).setShortcut(
				'0', 'a');
		menu.add(0, SETTING_ID, R.string.setting_menu).setShortcut(
				'1','s');
		return true;
	}
	@Override
	protected void onDestroy(){
		super.onDestroy();
	}
	/**
	 * Called when a menu item is selected.
	 * 
	 * @param item
	 * 
	 */
	@Override
	public boolean onOptionsItemSelected(Menu.Item item) {

		switch (item.getId()) {
		case ABOUT_ID:
			aboutScreen();
			return true;
		case SETTING_ID:
			settingsScreen();
			return true;
		}
		return super.onOptionsItemSelected(item);
	}
/**
 * Displays a About dialog 
 */
	public void aboutScreen() {
		String title= this.getResources().getString(R.string.about_title);
		String text= this.getResources().getString(R.string.about_text);
		String ok=getResources().getString(R.string.about_ok);
		AlertDialog.show(this, title,R.drawable.icon, text, ok, true);
	}
	/**
	 * starts the settings activity
	 */
	public void settingsScreen() {
		startActivity(TransitConst.SETTINGS_INTENT);
	}
}